package com.fatdetection.demo.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fatdetection.demo.bean.Relation;
import com.fatdetection.demo.mapper.RelationMapper;
import com.fatdetection.demo.service.RelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RelationServiceImp implements RelationService{
    @Autowired
    RelationMapper relationMapper;

    @Override
    public Boolean insertRelation(Relation relation) {
        return relationMapper.insert(relation) == 1;
    }

    @Override
    public Boolean delRelation(Integer id) {
        return relationMapper.delete(new QueryWrapper<Relation>().eq("id", id)) == 1;
    }

    @Override
    public Boolean updateRelation(Relation relation) {
        return relationMapper.update(relation, null) == 1;
    }

    @Override
    public List<Relation> findAll() {
        return relationMapper.selectList(null);
    }

    @Override
    public List<Relation> findBySchool(String schoolName) {
        return relationMapper.selectList(new QueryWrapper<Relation>().eq("schoolName", schoolName));
    }

    @Override
    public List<Relation> findByProj(String projName) {
        return relationMapper.selectList(new QueryWrapper<Relation>().eq("projectName", projName));
    }

    @Override
    public Relation findById(Integer id) {
        return relationMapper.selectOne(new QueryWrapper<Relation>().eq("id", id));
    }
}
